package com.sgx.learning.luban.homework.attributes;

import com.sgx.learning.luban.homework.attributes.ext.LineNumber;
import com.sgx.learning.luban.homework.basictype.U2;
import com.sgx.learning.luban.homework.constantpool.ConstantPoolInfo;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;

@Data
public class LineNumberTable extends AttributeInfo{

    private short lineNumberTableLength;

    private LineNumber[] lineNumbers;


    @Override
    public void read(InputStream is, ConstantPoolInfo[] constantPoolInfos) throws IOException {
        this.lineNumberTableLength = U2.read(is).getValue();
        if(this.lineNumberTableLength > 0) {
            this.lineNumbers = new LineNumber[lineNumberTableLength];
            for (int i = 0; i < lineNumberTableLength; i++) {
                LineNumber temp = new LineNumber();
                temp.read(is);
                this.lineNumbers[i] = temp;
            }
        }
    }
}
